package com.codegen;

import freemarker.template.Configuration;
import freemarker.template.Template;

import java.io.File;
import java.io.IOException;
import java.io.Writer;

public class TemplateEngine {
    private Configuration cfg;

    public TemplateEngine(String templateDir) throws IOException {
        cfg = new Configuration(Configuration.VERSION_2_3_31);
        cfg.setDirectoryForTemplateLoading(new File(templateDir));
        cfg.setDefaultEncoding("UTF-8");
    }

    public void processTemplate(String templateName, Object data, Writer out) throws Exception {
        Template template = cfg.getTemplate(templateName);
        template.process(data, out);
    }
}